<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>库存统计</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all" />
    <script src="layui/layui.js" type="text/javascript"></script>
</head>
<body>
<script type="text/html" class="demoTable" id="inventoryDiv" >
    <div class="layui-inline layui-show-xs-block">
        <label class="layui-form-label" style="width: 110px;text-align: center">业务日期</label>

        <div class="layui-inline layui-show-xs-block">
            <input  name="dateTime" lay-verify="required" autocomplete="off" placeholder="请选择日期" class="layui-input" id="dateTime">
        </div>
    </div>
    <button class="layui-btn" data-type="reload" lay-event="statistical"><i class="layui-icon layui-icon-table"></i>统计</button>
    <input type="hidden" name="fundId" id="fundId" value="000899"/>
</script>
<script>
    layui.use(['table','laydate'],function () {
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var laydate = layui.laydate;

        table.render({
            elem:'#inventoryTable',
            url:'selectInventory',
            toolbar:'#inventoryDiv',
            cellMinWidth: 80,
            cols:[[
                {type: 'checkbox'}
                ,{field:'inventoryName',title: '库存名称'}
                ,{field:'fundId',title: '基金编号'}
                ,{field:'inventoryOperator',title: '操作员'}
                ,{field:'inventoryDate',title: '统计日期'}
                ,{field:'inventoryNum',title: '统计数量'}
                ,{field:'inventoryStatis',title: '统计状态'}
            ]]
        })
        laydate.render({
            elem:'#dateTime',
            trigger:'click'
        });
        table.on('toolbar(inventoryTable)',function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);//得到表格选中行的ID
            switch (obj.event) {
                case 'statistical':
                    var data = checkStatus.data;
                    var dateTime = $("#dateTime").val();
                    var fundId=$("#fundId").val();
                    if (data.length == 0) {
                        layer.msg("请至少选择一个库存进行统计")
                    } else {
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].id);
                        }
                    }
                    laydate.render({
                        elem:'#dateTime',
                        trigger:'click'
                    });
                    table.reload('inventoryTable', {
                            method: 'post'
                            , where: {
                                'dateTime': dateTime,
                                'id': ids.join(','),
                                'fundId':fundId
                            }

                        }
                    );
                    laydate.render({
                        elem:'#dateTime',
                        trigger:'click'
                    });
                    break;
            }
        })
    })
</script>

<table id="inventoryTable" lay-filter="inventoryTable"></table>
</body>
</html>